import axios from "axios"

axios.defaults.baseURL = 'http://localhost:3000/';
const token = localStorage.getItem("token")
console.log(token)
axios.defaults.headers.common['token'] = token;



axios.interceptors.request.use(
    (config) => {
        return config
    },
    (error) => {
        return Promise.reject(error);
    }
)


// 添加响应拦截器
axios.interceptors.response.use(
    (response) => {
        if (response.data.code === '500') {
            alert("服务器错误")
        }
        return response.data;
    },
    (error) => {
        if (error.response.status == 404) {
            alert("404")
        }
        return Promise.reject(error);
    }
);

export default axios

